package com.briup.shopadmin.web.controller;

import com.briup.shopadmin.common.Result;
import com.briup.shopadmin.common.bean.Shop;
import com.briup.shopadmin.service.IShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "商品管理相关接口")
@RequestMapping("shop")
public class ShopController {
    @Autowired
    IShopService shopService;

    @GetMapping("findShopInfo")
    @ApiOperation("分⻚查询商品信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "shopName", value = "商品名称", defaultValue = ""),
            @ApiImplicitParam(name = "pageNum", value = "⻚码", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每⻚展示数据条数", required = true),


    })
    public Result findShopInfo(@RequestParam(required = false, defaultValue = "") String shopName, Integer pageNum, Integer pageSize) {
        Page page = shopService.findAllByName(shopName, pageNum, pageSize);
        return Result.success(page);
    }

    @PostMapping("saveShop")
    @ApiOperation("新增/修改商品")
    public Result saveShop(@RequestBody Shop shop) {
        shopService.save(shop);
        return Result.success();
    }

    @PutMapping("updateShopStatus/{id}")
    @ApiOperation("修改商品在售状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "商品编号")
    })
    public Result updateShopStatus(@PathVariable long id) {
        shopService.updateShopStatus(id);
        return Result.success();
    }
    @GetMapping("getShopInfo/{id}")
    @ApiOperation("获取商品详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "商品编号")
    })
    public Result getShopInfo(@PathVariable long id){

        Shop shop = shopService.getShopInfo(id);
        return  Result.success(shop);
    }
}